/**
 * 详情对话框
 */
var FlowServiceTypeInfoDlg = {
    data: {
        serviceTypeId: "",
        typeName: "",
        typeUrl: "",
        notes: "",
        memberNumber: "",
        params: "",
        type:"",
        orders: "",
        module:"",
        status:""
    }
};

layui.use(['form', 'admin', 'ax','laydate','upload','formSelects'], function () {
    var $ = layui.jquery;
    var $ax = layui.ax;
    var form = layui.form;
    var admin = layui.admin;








    //普通图片上传
    var upload = layui.upload;
    upload.render({
        elem: '#typeUrlBtn'
        ,url: Feng.ctxPath + '/system/upload' //改成您自己的上传接口
        ,before: function(obj){
            //预读本地文件示例，不支持ie8
            obj.preview(function(index, file, result){
                $('#filePreview').attr('src', result); //图片链接（base64）
            });
        }
        ,done: function(res){
            $("#typeUrl").val("/upload/"+res.data.fileName);
            Feng.success(res.message);
        }
        ,error: function(){
            Feng.error("上传文件失败！");
        }
    });








    //获取详情信息，填充表单
    var ajax = new $ax(Feng.ctxPath + "/flowServiceType/detail?serviceTypeId=" + Feng.getUrlParam("serviceTypeId"));
    var result = ajax.start();
    form.val('flowServiceTypeForm', result.data);
    $("#filePreview").attr('src',result.data.typeUrl);

    //
    var params = result.data.params.split("[#]");
    var index = 0;
    $("#formList").find('.param-line').each(function () {
        var node = $(this);
        if(params.length > index){
            var p = params[index].split("[=]");
            node.find('input.param-key').val(p[0]);
            node.find('input.param-value').val(p[1]);
            index++;
        }
    });

    //表单提交事件
    form.on('submit(btnSubmit)', function (data) {

        var params = "";
        $("#formList").find('.param-line').each(function () {
            var node = $(this);
            var key = node.find('input.param-key').val();
            var value = node.find('input.param-value').val();
            if(key && value){
                if(params){
                    params += "[#]"+key+"[=]"+value;
                }else {
                    params += key+"[=]"+value;
                }
            }
        });
        data.field.params = params;
        var ajax = new $ax(Feng.ctxPath + "/flowServiceType/editItem", function (data) {
            Feng.success("更新成功！");
            //传给上个页面，刷新table用
            admin.putTempData('formOk', true);
            //关掉对话框
            admin.closeThisDialog();
        }, function (data) {
            Feng.error("更新失败！" + data.responseJSON.message)
        });
        ajax.set(data.field);
        ajax.start();

        return false;
    });

});